﻿/********************************************************************************
 * This code is provided as-is, with no explicit or implicit guaranties         *
 * and is governed by the Common Creative License.                              *
 *                                                                              *
 * If you find this code useful and decide to use it for your                   *
 * own proyects, please be sure to copy this complete header, along             *
 * with the authors name.                                                       *
 *                                                                              *
 * A link back from your personal site to the articles URL                      *
 * will also be appreciated                                                     *
 *                                                                              *
 * @author: Matthias Reichenbach                                                *
 * (http://www.codeproject.com/script/Membership/Profiles.aspx?mid=3576642)     *
 *                                                                              *
 * ******************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FuzzyLogic
{
    class InverseTrapezoidalMembershipFunction : IMembershipFunction
    {
        double a, b, c, d;

        public InverseTrapezoidalMembershipFunction(double a, double b, double c, double d)
        {
            this.a = a;
            this.b = b;
            this.c = c;
            this.d = d;
        }
        #region IMembershipFunction Members

        public double MembershipOf(double value)
        {
            if ((a < value) && (value <= b))
                return (b - value) / (b - a);
            if ((b < value) && (value <= c))
                return 0;
            if ((c < value) && (value < d))
                return (value - c) / (d - c);
            return 1;
        }

        #endregion
    }
}
